package com.example.huaweiiot_example_funiotxyz;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.makeText(MainActivity.this, "请查看Android Studio 控制台输出数据", Toast.LENGTH_LONG).show();
        //获取设备属性+在线状态
        final Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    HuaweiIOT hwiot = new HuaweiIOT();
                    String str = "";
                    str = hwiot.getAtt("temp", "shadow");
                    System.out.println("temp=" + str);
                    str = hwiot.getAtt("", "status");
                    System.out.println("status=" + str);
                    if(str.equals("ONLINE"))
                        str = hwiot.setCom("led", "0");
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("获取失败：" + e.toString());
                }
            }
        };
        t.start();
    }

}